#! /usr/bin/env python
#-*- coding: utf-8 -*-


def distinct(dicts, unique_id='id', replace=False):
    unique_ids = set()
    new_dicts = []
    for i in dicts:
        if i[unique_id] not in unique_ids:
            new_dicts.append(i)
            unique_ids.add(i[unique_id])
    if replace:
        for i in range(len(dicts)):
            dicts.pop()
        dicts.extend(new_dicts)
    return new_dicts


dicts = [{'id': 1}, {'id': 1}, {'id': 1}, {'id': 1}, {'id': 1}]
dicts_id = id(dicts)
print 'Before:'
print dicts
print dicts_id

new_dicts = distinct(dicts, replace=True)
print '\nAfter:'
print dicts
print id(dicts)

assert dicts == new_dicts and dicts_id ==  id(dicts)

print '\nNew DList ID:'
print id(new_dicts)